home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / STDLIB.PAK / MAX.CPP < prev    next >
Text File  |  1997-05-06  |  796b  |  33 lines

  1.  #include <algorithm>
  2.  
  3.  using namespace std;
  4.  
  5.  int main ()
  6.  {                            
  7.    double  d1 = 10.0, d2 = 20.0;
  8.    //
  9.    // Find minimum.
  10.    //
  11.    double val1 = min(d1, d2);
  12.    //
  13.    // The greater comparator returns the greater of the two values.
  14.    //
  15.    double val2 = min(d1, d2, greater<double>());
  16.    //
  17.    // Find minimum.
  18.    //
  19.    double val3 = max(d1, d2);
  20.    //
  21.    // The less comparator returns the smaller of the  two values.
  22.    // Note that, like every comparison in the STL, max is
  23.    // defined in terms of the < operator, so using less here
  24.    // is the same as using the max algorithm with a default
  25.    // comparator.
  26.    //
  27.    double val4 = max(d1, d2, less<double>());
  28.  
  29.    cout << val1 << " " << val2 << " " << val3 << " " << val4 << endl;
  30.  
  31.    return 0;
  32.  }
  33.